<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../static/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../static/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
	<div class="layui-form-item">
		<h2 align="center">重置密码</h2>
	</div>
	<div class="layui-form-item">
	    <label class="layui-form-label required">用户ID</label>
	    <div class="layui-input-block">
	        <input type="text" name="id" lay-verify="required" lay-reqtext="用户ID不能为空" disabled="disabled" value="" class="layui-input" >

	    </div>
	</div>
    <div class="layui-form-item">
        <label class="layui-form-label required">账号</label>
        <div class="layui-input-block">
            <input type="text" name="id_number" lay-verify="required" lay-reqtext="工号不能为空" disabled="disabled" value="" class="layui-input">
            <!-- <tip>填写自己管理账号的名称。</tip> -->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">新密码</label>
        <div class="layui-input-block">
            <input type="password" name="id_password" lay-verify="required" lay-reqtext="重置密码不能为空" placeholder="请输入新密码" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>

<script>
	function updateForm(data) {
		console.log(data);
		layui.use(['form', 'table'], function () {
			var $ = layui.jquery,
				form = layui.form;
			
			$("input[name='id']").val(data.id);
			$("input[name='id_number']").val(data.id_number);
			
			var token = "{{ csrf_token }}";
			$.ajaxSetup({
			    headers: { 
				 'X-CSRFTOKEN': `${token}`,
				 'AUTHORIZATION': 'Bearer ' + localStorage.token,
				 }, 
			});
			
			
			$(function(){   //js 加载时，AJAX请求
				  $.ajax({
					url:'/auth-query',
					type:'post',
					dataType:'json',
					success:function(result){
						console.log(result);
					},
					error:function(){
						layer.msg('授权查询API出错！');
					}
				})
			});
		});

	}	
	
</script>

<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
		
		var token = "{{ csrf_token }}"
		$.ajaxSetup({
		    headers: { 
			 'X-CSRFTOKEN': `${token}`,
			 'AUTHORIZATION': 'Bearer ' + localStorage.token,
			 }, // JWTAuthentication.authenticate()方法获取 header = request.META.get(api_settings.AUTH_HEADER_NAME),
		});
		
		$.ajaxSetup({
			complete: function (XMLHttpRequest, textStatus) {
				if (XMLHttpRequest.status === 401) {  // 401 表示未授权，即 token 无效
					layer.msg('授权已过期，需重新登陆', { icon: 2, time: 2000 }, function () {
						window.location.href = '/login';
					})
				}
			}
		});
		
        //监听提交
        form.on('submit(saveBtn)', function (data) {
			
			//传给后台
			$.ajax({
				url:"/admin-password-reset",
				type:"post",
				data:data.field,
				success:function(result){
					if (result.success){
						layer.msg(result.msg, { icon: 1, time: 2000 }, function () {
						  parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
						  parent.layui.table.reload('currentTableId')
						})
					}
					else{
						layer.alert(result.msg);
					}
					
				},
				error:function(result){
					alert("接口错误！！！");
				}
				});
			
			return false;
			
        });

    });
</script>
</body>
</html>